package cn.wolfcode.shop.controller;

import cn.wolfcode.shop.domain.SkuPropertyValue;
import cn.wolfcode.shop.service.ISkuPropertyValueService;
import cn.wolfcode.vo.JSONResultVo;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;

@Controller
@RequestMapping("/skuPropertyValue")
public class SkuPropertyValueController {

    @Reference
    private ISkuPropertyValueService skuPropertyValueService;

    /**
     * 查看属性值
     * @param skuPropertyId
     * @param model
     * @return
     */
    @RequestMapping("/get/{skuPropertyId}")
    public String skuPropertyValuePage(@PathVariable("skuPropertyId") Long skuPropertyId, Model model){

        model.addAttribute("skuPropertyValueList",skuPropertyValueService.queryByPropertyId(skuPropertyId));

       return "skuProperty/skuProperty_value_list";
    }


    @RequestMapping("/save")
    @ResponseBody
    public JSONResultVo batchSaveOrUpdate(@RequestBody List<SkuPropertyValue> skuPropertyValueList){

        skuPropertyValueService.batchSaveOrUpdate(skuPropertyValueList);
        return JSONResultVo.instance();
    }

    @RequestMapping("/delete/{id}")
    @ResponseBody
    public JSONResultVo delete(@PathVariable("id") Long skuPropertyValueId){

        skuPropertyValueService.deleteByPVId(skuPropertyValueId);
        return JSONResultVo.instance();
    }

}
